package com.hanrui.android.fragment.message;

import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;

import com.hanrui.android.R;
import com.hanrui.android.adapter.LcAdapter;
import com.hanrui.android.library.base.BaseFragment;
import com.hanrui.android.model.HistoricFlowBean;
import com.hanrui.android.net.contract.LcContract;
import com.hanrui.android.net.presenter.LcPresenter;

import java.util.List;

import butterknife.BindView;


/**
 * 流程图
 * Created by menglei on 2018/3/7.
 */

public class LcFragemnt extends BaseFragment<LcPresenter> implements LcContract.View {

    @BindView(R.id.lc_recyclerview)
    RecyclerView mRecyclerView;
    @BindView(R.id.emptyview_ll)
    LinearLayout emptyView;

    LcAdapter adapter;

    String taskId,procInsId,bizId;


    private void init() {

        taskId = getArguments().getString("taskId");
        procInsId = getArguments().getString("procInsId");
        bizId = getArguments().getString("bizId");

        mPresenter.loadData(getActivity(),procInsId,bizId);

        mRecyclerView.setBackgroundColor(ContextCompat.getColor(getActivity(),R.color.c_f1f1f1));
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        adapter = new LcAdapter();
        mRecyclerView.setAdapter(adapter);

    }

    //实例化
    public static LcFragemnt newInstance(String taskId,String procInsId,String bizId) {
        LcFragemnt fragemnt = new LcFragemnt();
        Bundle args = new Bundle();
        args.putString("taskId", taskId);
        args.putString("procInsId", procInsId);
        args.putString("bizId", bizId);
        fragemnt.setArguments(args);
        return fragemnt;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_lc;
    }

    @Override
    protected void initInjector() {
        mFragmentComponent.inject(this);
    }

    @Override
    protected void initView(View view) {
        init();
    }

    @Override
    public void loadData(List<HistoricFlowBean.HistoicFlowListBean> list) {

        if (null != list && list.size() > 0) {

            adapter.setNewData(list);
            return;
        }

        mRecyclerView.setVisibility(View.GONE);
        emptyView.setVisibility(View.VISIBLE);

    }
}
